package com.laxcen.basiclib.core.updateH5.task;

import com.laxcen.basiclib.BaseConst;
import com.laxcen.basiclib.core.task.Task;
import com.laxcen.basiclib.utils.FileUtil;
import com.laxcen.basiclib.utils.SharedPreferencesUtil;
import com.laxcen.basiclib.utils.ZipUtil;
import java.io.IOException;

public class H5UpdateTask extends Task {
    @Override
    public Task doTask() {
       Callback callback  = getParam("callback");
       String path = getParam("path");
       String h5Path = FileUtil.getNewH5VersionPath();
        try {
            ZipUtil.unZip(path,h5Path,callback);
            SharedPreferencesUtil.putData(BaseConst.NEW_VERSION_LOAD_PATH,path);
        } catch (IOException e) {
            e.printStackTrace();
            callback.onResult(false,e.getMessage());
        }
        return this;
    }

    public interface Callback{
        void onProgress(int i);
        void onResult(boolean isOk,String msg);
    }
}
